package com.ruoyi.personnel.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.personnel.domain.Department;
import com.ruoyi.personnel.mapper.DepartmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.personnel.mapper.EmployeeMapper;
import com.ruoyi.personnel.domain.Employee;
import com.ruoyi.personnel.service.IEmployeeService;

/**
 * 员工管理Service业务层处理
 *
 * @author ruoyi
 * @date 2023-03-03
 */
@Service
public class EmployeeServiceImpl  implements IEmployeeService
{
    @Autowired
    private EmployeeMapper employeeMapper;

    @Autowired
    private DepartmentMapper departmentMapper;

    /**
     * 查询员工管理
     *
     * @param empId 员工管理主键
     * @return 员工管理
     */
    @Override
    public Employee selectEmployeeByEmpId(Integer empId)
    {
        return employeeMapper.selectEmployeeByEmpId(empId);
    }

    /**
     * 查询员工管理列表
     *
     * @param employee 员工管理
     * @return 员工管理
     */
    @Override
    public List<Employee> selectEmployeeList(Employee employee)
    {

        List<Employee> employeeList = employeeMapper.selectEmployeeList(employee);
        for (Employee emp : employeeList) {
            Department department = departmentMapper.selectDepartmentByDepId(emp.getDepId());
            emp.setDepName(department.getDepName());
        }
        return employeeList;
    }

    /**
     * 新增员工管理
     *
     * @param employee 员工管理
     * @return 结果
     */
    @Override
    public int insertEmployee(Employee employee)
    {
        employee.setCreateTime(DateUtils.getNowDate());
        return employeeMapper.insertEmployee(employee);
    }

    /**
     * 修改员工管理
     *
     * @param employee 员工管理
     * @return 结果
     */
    @Override
    public int updateEmployee(Employee employee)
    {
        employee.setUpdateTime(DateUtils.getNowDate());
        return employeeMapper.updateEmployee(employee);
    }

    /**
     * 批量删除员工管理
     *
     * @param empIds 需要删除的员工管理主键
     * @return 结果
     */
    @Override
    public int deleteEmployeeByEmpIds(Integer[] empIds)
    {
        return employeeMapper.deleteEmployeeByEmpIds(empIds);
    }

    /**
     * 删除员工管理信息
     *
     * @param empId 员工管理主键
     * @return 结果
     */
    @Override
    public int deleteEmployeeByEmpId(Integer empId)
    {
        return employeeMapper.deleteEmployeeByEmpId(empId);
    }

    @Override
    public void rollbackEmployee(Object[] array) {
        employeeMapper.rollbackEmployee(array);
    }
}
